<template>
  <div class="container">
    <div class="header">
      <el-input
        v-model="input"
        placeholder="请输入菜品名称"
        clearable
        @keyup.native.enter="handleSearch"
      >
        <i
          slot="prefix"
          class="el-input__icon el-icon-search"
          @click="handleSearch"
        ></i>
      </el-input>
      <div class="mid"></div>
      <div class="right">
        <el-link type="danger">批量删除</el-link>
        <el-divider direction="vertical"></el-divider>
        <el-link type="primary">批量启售</el-link>
        <el-divider direction="vertical"></el-divider>
        <el-link type="danger">批量停售</el-link>
        <el-button
          type="primary"
          icon="el-icon-plus"
          @click="$router.push()"
          >新建菜品</el-button
        >
      </div>
    </div>

    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column
            type="selection"
            width="55">
      </el-table-column>
      <el-table-column prop="name" label="菜品名称"> </el-table-column>
      <el-table-column label="图片" width="80">
        <template v-slot="{ row }">
          <el-image
            style="width: 50px; height: 50px"
            :src="baseUrl+row.image"
            :fit="fit"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="categoryName" label="菜品分类"> </el-table-column>
      <el-table-column label="售价">
        <template v-slot="{ row }">
          ¥{{ row.price  }}
        </template>
      </el-table-column>
      <el-table-column label="售卖状态">
        <template v-slot="{ row }">
          {{ row.status ? "启售" : "停售" }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="最后操作时间"> </el-table-column>
      <el-table-column label="操作" header-align="center" align="center">
        <template v-slot="{ row }">
          <el-link type="primary">修改</el-link>
           <el-divider direction="vertical"></el-divider>
           <el-link type="primary">停售</el-link>
           <el-divider direction="vertical"></el-divider>
          <!-- <el-popconfirm
             title="确认调整该账号的状态?"
             @onConfirm="handleChangeStatus(row)"
           > -->
           <el-link type="danger">删除</el-link>
           <!-- </el-popconfirm> -->
        </template>
      </el-table-column>
    </el-table>
    <div class="footer">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageInfo.page"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pageInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getdishes } from "@/api/dish";
export default {
  data() {
    return {
      pageInfo: {
        page: 1,
        pageSize: 10,
      },
      total: 0,
      input: "",
      tableData: [],
      baseUrl:'http://162.14.124.240:8080/common/download?name='
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      getdishes(this.pageInfo).then(res=>{
        this.tableData = res.data.records;
        this.total = res.data.total;
      })
    },
    handleSizeChange(val) {
      this.pageInfo.page = 1;
      this.pageInfo.pageSize = val;
      this.init();
    },
    handleCurrentChange(val) {
      this.pageInfo.page = val;
      this.init();
    },
    handleSearch() {
      this.pageInfo.page = 1;
      this.init();
    },
    handleChangeStatus(row) {
      changeStatus({ id: row.id, status: +!row.status }).then((res) => {
        this.$message.success("改变成功");
        this.init();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  padding: 22px;
  .header {
    display: flex;
    // justify-content: space-between;
    .el-input {
      width: 250px;
    }
    .mid{
      flex: 1;
    }
    .right{
      width: 400px;
      // width: 800px;
      // width: 400px;
      display: flex;
      flex-direction: row;
      justify-content: space-around;
      align-items: center;
    }
  }
  .el-table {
    margin-top: 20px;
  }
  .footer {
    margin-top: 22px;
    display: flex;
    justify-content: center;
  }
}
</style>
